<?php

require_once('record.php');

class kategori extends record {

    protected $authRep = '';

    function __construct() {
        parent::__construct();
        $this->namaTabel = 'kategori';
        $this->authRep = new amankanParam();
    }

    function getCombo($useNullVal = true,$emptyKat = '') {
        $str = '';
        $this->get('*', array('aktif' => 1));
        $dt = $this->execute();
        if ($dt['success'] == true && $dt['total'] > 0) {
            $str .=($useNullVal==true)?"<option>".$emptyKat."</option>":'';
            foreach ($dt['result'] as $kaT) {
                $str .="<option value='" . $kaT['id'] . "'>" . $kaT['nama'] . "</option>";
            }
        } else {
        $str .= "<option>(data kosong)</option>";    
        };
        return $str;
    }
    function getDataAktif(){
        $this->get('id,nama', array('aktif'=>1),NULL,NULL,'nama');
        return $this->execute();
    }

    function getData($limit = null, $start = null) {
        $this->num_rows();
        $total = $this->execute();
        $jml = ($total['success'] == true) ? $total['result'][0]['total'] : 0;
        $this->get('*', array(), $limit, $start);
        $data = $this->execute();
        $dtS = ($data['success'] == TRUE) ? $data['result'] : array();
        $return = array('total' => $jml, 'result' => $dtS);
        return $return;
    }

    function ubahAktif() {
        $dtPost = $this->authRep->postMethod();
        $arrW = array('id' => $dtPost['id']);
        $this->update(array('aktif' => 0), $arrW);
    }

}
 $objKategori = new kategori();